<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>

    // es5
    function date() {
        // 是一个对象
        console.log(arguments);
        for (let i = 0; i < arguments.length; i++) {
            console.log(arguments[i]);
        }
    }
    date("mortal", "nanfeng");

    // es6引入rest参数用于替代arguments对象
    function sum(...args) {
        // 是一个数组
        console.log(args); // [1,2,3,4,5,6,7,8,9,10]
        let sum = 0;
        for (let i = 0; i < args.length; i++) {
            sum += args[i];
        }
        return sum;
    }
    let res = sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    console.log(res);

    // 注意：rest参数只能是最后一个参数
    function fn(a, b, ...args) {
        console.log(args);// [3,4,5,6,7,8,9,10]
    }
    fn(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

    // es9 rest 参数的对对象的支持
    function fn({ name, ...user }) {
        console.log(name, user); // mortal {age: 18, address: '上海'}
    }
    fn({ name: 'mortal', age: 18, address: '上海' });

    const skillOne = {
        q: "金钟罩"
    }
    const skillTwo = {
        w: "铁布衫"
    }
    const skillThree = {
        e: "天雷破"
    }
    const skillFour = {
        r: "猛龙摆尾"
    }
    const mangsheng = {
        ...skillOne,
        ...skillTwo,
        ...skillThree,
        ...skillFour
    }
    console.log(mangsheng); // { q: '金钟罩', w: '铁布衫', e: '天雷破', r: '猛龙摆尾' }


</script>

</html>